﻿using ConfExpert.Forms.Base;
using DevExpress.Utils;
using DevTeam;
using System;
using System.Drawing;
using System.Windows.Forms;

namespace ConfExpert.Forms.Depo
{
    public partial class Du4Articles : XForm
    {
        public Du4Articles()
        {
            InitializeComponent();
        }

        BindingSource bs;
        private void Du4Articles_Load(object sender, EventArgs e)
        {
            
            ds.xDu4Art.Columns.Add("Id", typeof(int), "ProductId");

            bs = new BindingSource(ds, "xDu4Art");
            AddBsToList(bs);
            InitGridView(gridView1, bs);
            gridView1.MakeColumnInvisible("UreticiKodlariId", "ProductId");
            gridView1.Columns["Id"].VisibleIndex = 0;
            gridView1.ShowFindPanel();
            gridView1.AddSummary();

            TAM.xDu4ArtTableAdapter = new Datasets.MyDataTableAdapters.xDu4ArtTableAdapter();
            TAM.xDu4ArtTableAdapter.Fill(ds.xDu4Art);
            gridView1.BestFitColumns();

            gridView1.RowCellStyle += new DevExpress.XtraGrid.Views.Grid.RowCellStyleEventHandler(gridView1_RowCellStyle);
            
            btnEkle.Visibility = btnKaydet.Visibility = ytk(106) ? DevExpress.XtraBars.BarItemVisibility.Always :  DevExpress.XtraBars.BarItemVisibility.Never;
            btnKaydet.ItemClick += btnKaydet_ItemClick;
            btnEkle.ItemClick += btnEkle_ItemClick;
        }

        void btnEkle_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            btnKaydet.PerformClick();
            GetDetails("xDu4Art", "UpdDu4Art");
            if (ds.xBuffer.Rows.Count > 0)
            {
                Notify(ds.xBuffer.Rows[0]["intVal"].ToString() + " yeni kayıt eklendi.");
                //    ds.xBuffer.Clear();
            }
        }

        void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ds.xDu4Art.Columns["Id"].Expression = string.Empty;
            Save();
            ds.xDu4Art.Columns["Id"].Expression = "ProductId";
        }

        
        void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            if (e.RowHandle > -1)
            {
                if (e.Column.FieldName.StartsWith("Yeni"))
                    e.Appearance.Font = new Font(AppearanceObject.DefaultFont, FontStyle.Bold);

                else if (e.Column.FieldName == "Id")
                    e.Appearance.ForeColor = Color.Indigo;

            }
        }

        


    }
}